home *** CD-ROM | disk | FTP | other *** search
- Path: newsfeed.internetmci.com!xmission!news
- From: macron@xmission.com (Joe Schlimgen)
- Newsgroups: comp.lang.c++
- Subject: auto_ptr capability question
- Date: Mon, 01 Apr 1996 17:17:51 GMT
- Organization: XMission Internet (801 539 0900)
- Message-ID: <31600aa3.1288774@news.xmission.com>
- NNTP-Posting-Host: slc43.xmission.com
- X-Newsreader: Forte Agent .99d/32.182
-
- Before the STL, I created my own auto_ptr like class. Now that I have
- the STL (provided with BC++ 5.0), I've decided to use the standard
- auto_ptr.
-
- My class has a conversion from auto_ptr<X> to X* (shown below). This
- made it very easy to use an auto_ptr just like a pointer. The STL does
- not provide an implicit conversion, you must use the get() member
- function.
-
- Can anyone provide a reason why the designers of the STL (who, I would
- think, are much more knowledgeable about C++ and OOP than I) would
- choose to provide an explicit rather than an implicit function? I see no
- potential problems with an implicit conversion (but I could very well be
- wrong).
-
- Also, I've noticed that the assignment from another auto_ptr function
- (also shown below) causes the auto_ptr being assign *from* to release
- ownership (as it should) but does *not* delete the (possible) pointer
- that is being assigned *to*, thus possibly causing a memory leak.
-
- Is this a bug, or is it intentional? If intentional, why?
-
- Pertinent parts of the auto_ptr class:
-
- template<class X> class auto_ptr
- {
- // ...
-
- X* get () const { return the_p; } // Provided by the STL
- X* operator X* () const { return the_p; } // Not provided by the STL
-
- // ...
-
- void operator= (auto_ptr<X>& rhs) { reset(rhs.release()); }
- X* reset (X* p = 0) { X* tmp = the_p; the_p = p; return tmp; }
-
- // ...
- }
-
-
-
- -- The Truth Is Out There --
-